﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.IO;
using iTeachSoft.CoreObjects;
using iTeachSoft.Code.Managers;
using iTeachSoft.Presentation.Code.Managers;

namespace iTeachSoft.Presentation.Dialogs
{
    /// <summary>
    /// Interaction logic for DialogNewProject.xaml
    /// </summary>
    public partial class DialogNewProject : Window
    {
        public DialogNewProject()
        {
            InitializeComponent();

            LoadDefalutValues();
        }

        private void LoadDefalutValues()
        {
            textBoxFrameWidth.Text = "800";
            textBoxFrameHeight.Text = "600";

            textBoxProjectName.Text = "Untitled";
            textBoxProjectPath.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        }

        private bool IsValidData()
        {
            return true;
        }

        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            //TODO add validations
            this.Close();
        }

        private void buttonOk_Click(object sender, RoutedEventArgs e)
        {
            if (IsValidData())
            {
                Project newProject = new Project();
                newProject.Name = textBoxProjectName.Text;
                newProject.ProjectPath = textBoxProjectPath.Text;

                int width = int.Parse(textBoxFrameWidth.Text);
                int height = int.Parse(textBoxFrameHeight.Text);

                newProject.SlidesSize = new System.Drawing.Size(width, height);

                RuntimeStorage.CurrentProject = newProject;
                //Reflect the new project
                EventsManagement.Instance.OnReflectProjectInvoked(this, EventArgs.Empty);
                this.Close();
            }
        }

        private void buttonBrowse_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            if (Directory.Exists(textBoxProjectPath.Text))
                dlg.InitialDirectory = textBoxProjectPath.Text;
            else
                dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            dlg.Filter = "iTeachSoft files | *.its";

            bool result = dlg.ShowDialog(this).Value;
            if (result)
                textBoxProjectPath.Text = dlg.FileName;
        }

    }
}
